<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>enterhandler_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_enterhandler_test.js.html">enterhandler_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.EnterHandlerTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.EnterHandlerTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line20"></a>goog.require(&#39;goog.dom.Range&#39;);
<a name="line21"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line22"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line23"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line24"></a>goog.require(&#39;goog.editor.Plugin&#39;);
<a name="line25"></a>goog.require(&#39;goog.editor.plugins.Blockquote&#39;);
<a name="line26"></a>goog.require(&#39;goog.editor.plugins.EnterHandler&#39;);
<a name="line27"></a>goog.require(&#39;goog.editor.range&#39;);
<a name="line28"></a>goog.require(&#39;goog.events&#39;);
<a name="line29"></a>goog.require(&#39;goog.events.KeyCodes&#39;);
<a name="line30"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line31"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line32"></a>goog.require(&#39;goog.testing.dom&#39;);
<a name="line33"></a>goog.require(&#39;goog.testing.editor.TestHelper&#39;);
<a name="line34"></a>goog.require(&#39;goog.testing.events&#39;);
<a name="line35"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line36"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line37"></a>
<a name="line38"></a>var savedHtml;
<a name="line39"></a>
<a name="line40"></a>var field1;
<a name="line41"></a>var field2;
<a name="line42"></a>var firedDelayedChange;
<a name="line43"></a>var firedBeforeChange;
<a name="line44"></a>var clock;
<a name="line45"></a>var container;
<a name="line46"></a>var EXPECTEDFAILURES;
<a name="line47"></a>
<a name="line48"></a>function setUpPage() {
<a name="line49"></a>  container = goog.dom.getElement(&#39;container&#39;);
<a name="line50"></a>}
<a name="line51"></a>
<a name="line52"></a>function setUp() {
<a name="line53"></a>  EXPECTEDFAILURES = new goog.testing.ExpectedFailures();
<a name="line54"></a>  savedHtml = goog.dom.getElement(&#39;root&#39;).innerHTML;
<a name="line55"></a>  clock = new goog.testing.MockClock(true);
<a name="line56"></a>}
<a name="line57"></a>
<a name="line58"></a>function setUpFields(classnameRequiredToSplitBlockquote) {
<a name="line59"></a>  field1 = makeField(&#39;field1&#39;, classnameRequiredToSplitBlockquote);
<a name="line60"></a>  field2 = makeField(&#39;field2&#39;, classnameRequiredToSplitBlockquote);
<a name="line61"></a>
<a name="line62"></a>  field1.makeEditable();
<a name="line63"></a>  field2.makeEditable();
<a name="line64"></a>}
<a name="line65"></a>
<a name="line66"></a>function tearDown() {
<a name="line67"></a>  clock.dispose();
<a name="line68"></a>
<a name="line69"></a>  EXPECTEDFAILURES.handleTearDown();
<a name="line70"></a>
<a name="line71"></a>  goog.dom.getElement(&#39;root&#39;).innerHTML = savedHtml;
<a name="line72"></a>}
<a name="line73"></a>
<a name="line74"></a>function testEnterInNonSetupBlockquote() {
<a name="line75"></a>  setUpFields(true);
<a name="line76"></a>  resetChangeFlags();
<a name="line77"></a>  var prevented = !selectNodeAndHitEnter(field1, &#39;field1cursor&#39;);
<a name="line78"></a>  waitForChangeEvents();
<a name="line79"></a>  assertChangeFlags();
<a name="line80"></a>
<a name="line81"></a>  // make sure there&#39;s just one blockquote, and that the text has been deleted.
<a name="line82"></a>  var elem = field1.getElement();
<a name="line83"></a>  var dom = field1.getEditableDomHelper();
<a name="line84"></a>  EXPECTEDFAILURES.expectFailureFor(goog.userAgent.OPERA,
<a name="line85"></a>      &#39;The blockquote is overwritten with DIV due to CORE-22104 -- Opera &#39; +
<a name="line86"></a>      &#39;overwrites the BLOCKQUOTE ancestor with DIV when doing FormatBlock &#39; +
<a name="line87"></a>      &#39;for DIV&#39;);
<a name="line88"></a>  try {
<a name="line89"></a>    assertEquals(&#39;Blockquote should not be split&#39;,
<a name="line90"></a>        1, dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem).length);
<a name="line91"></a>  } catch (e) {
<a name="line92"></a>    EXPECTEDFAILURES.handleException(e);
<a name="line93"></a>  }
<a name="line94"></a>  assert(&#39;Selection should be deleted&#39;,
<a name="line95"></a>      -1 == elem.innerHTML.indexOf(&#39;selection&#39;));
<a name="line96"></a>
<a name="line97"></a>  assertEquals(&#39;The event should have been prevented only on webkit&#39;,
<a name="line98"></a>      prevented, goog.userAgent.WEBKIT);
<a name="line99"></a>}
<a name="line100"></a>
<a name="line101"></a>function testEnterInSetupBlockquote() {
<a name="line102"></a>  setUpFields(true);
<a name="line103"></a>  resetChangeFlags();
<a name="line104"></a>  var prevented = !selectNodeAndHitEnter(field2, &#39;field2cursor&#39;);
<a name="line105"></a>  waitForChangeEvents();
<a name="line106"></a>  assertChangeFlags();
<a name="line107"></a>
<a name="line108"></a>  // make sure there are two blockquotes, and a DIV with nbsp in the middle.
<a name="line109"></a>  var elem = field2.getElement();
<a name="line110"></a>  var dom = field2.getEditableDomHelper();
<a name="line111"></a>  assertEquals(&#39;Blockquote should be split&#39;, 2,
<a name="line112"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem).length);
<a name="line113"></a>  assert(&#39;Selection should be deleted&#39;,
<a name="line114"></a>      -1 == elem.innerHTML.indexOf(&#39;selection&#39;));
<a name="line115"></a>
<a name="line116"></a>  assert(&#39;should have div with &amp;nbsp;&#39;,
<a name="line117"></a>      -1 != elem.innerHTML.indexOf(&#39;&gt;&#39; + getNbsp() + &#39;&lt;&#39;));
<a name="line118"></a>  assert(&#39;event should have been prevented&#39;, prevented);
<a name="line119"></a>}
<a name="line120"></a>
<a name="line121"></a>function testEnterInNonSetupBlockquoteWhenClassnameIsNotRequired() {
<a name="line122"></a>  setUpFields(false);
<a name="line123"></a>
<a name="line124"></a>  resetChangeFlags();
<a name="line125"></a>  var prevented = !selectNodeAndHitEnter(field1, &#39;field1cursor&#39;);
<a name="line126"></a>  waitForChangeEvents();
<a name="line127"></a>  assertChangeFlags();
<a name="line128"></a>
<a name="line129"></a>  // make sure there are two blockquotes, and a DIV with nbsp in the middle.
<a name="line130"></a>  var elem = field1.getElement();
<a name="line131"></a>  var dom = field1.getEditableDomHelper();
<a name="line132"></a>  assertEquals(&#39;Blockquote should be split&#39;, 2,
<a name="line133"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem).length);
<a name="line134"></a>  assert(&#39;Selection should be deleted&#39;,
<a name="line135"></a>      -1 == elem.innerHTML.indexOf(&#39;selection&#39;));
<a name="line136"></a>
<a name="line137"></a>  assert(&#39;should have div with &amp;nbsp;&#39;,
<a name="line138"></a>      -1 != elem.innerHTML.indexOf(&#39;&gt;&#39; + getNbsp() + &#39;&lt;&#39;));
<a name="line139"></a>  assert(&#39;event should have been prevented&#39;, prevented);
<a name="line140"></a>}
<a name="line141"></a>
<a name="line142"></a>function testEnterInBlockquoteCreatesDivInBrMode() {
<a name="line143"></a>  setUpFields(true);
<a name="line144"></a>  selectNodeAndHitEnter(field2, &#39;field2cursor&#39;);
<a name="line145"></a>  var elem = field2.getElement();
<a name="line146"></a>  var dom = field2.getEditableDomHelper();
<a name="line147"></a>
<a name="line148"></a>  var firstBlockquote =
<a name="line149"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[0];
<a name="line150"></a>  var div = dom.getNextElementSibling(firstBlockquote);
<a name="line151"></a>  assertEquals(&#39;Element after blockquote should be a div&#39;, &#39;DIV&#39;, div.tagName);
<a name="line152"></a>  assertEquals(&#39;Element after div should be second blockquote&#39;,
<a name="line153"></a>      &#39;BLOCKQUOTE&#39;, dom.getNextElementSibling(div).tagName);
<a name="line154"></a>}
<a name="line155"></a>
<a name="line156"></a>
<a name="line157"></a>/**
<a name="line158"></a> * Tests that breaking after a BR doesn&#39;t result in unnecessary newlines.
<a name="line159"></a> * @bug 1471047
<a name="line160"></a> */
<a name="line161"></a>function testEnterInBlockquoteRemovesUnnecessaryBrWithCursorAfterBr() {
<a name="line162"></a>  setUpFields(true);
<a name="line163"></a>
<a name="line164"></a>  // Assume the following HTML snippet:-
<a name="line165"></a>  // &lt;blockquote&gt;one&lt;br&gt;|two&lt;br&gt;&lt;/blockquote&gt;
<a name="line166"></a>  //
<a name="line167"></a>  // After enter on the cursor position without the fix, the resulting HTML
<a name="line168"></a>  // after the blockquote split was:-
<a name="line169"></a>  // &lt;blockquote&gt;one&lt;/blockquote&gt;
<a name="line170"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line171"></a>  // &lt;blockquote&gt;&lt;br&gt;two&lt;br&gt;&lt;/blockquote&gt;
<a name="line172"></a>  //
<a name="line173"></a>  // This creates the impression on an unnecessary newline. The resulting HTML
<a name="line174"></a>  // after the fix is:-
<a name="line175"></a>  //
<a name="line176"></a>  // &lt;blockquote&gt;one&lt;br&gt;&lt;/blockquote&gt;
<a name="line177"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line178"></a>  // &lt;blockquote&gt;two&lt;br&gt;&lt;/blockquote&gt;
<a name="line179"></a>  field1.setHtml(false,
<a name="line180"></a>      &#39;&lt;blockquote id=&quot;quote&quot; class=&quot;tr_bq&quot;&gt;one&lt;br&gt;&#39; +
<a name="line181"></a>      &#39;two&lt;br&gt;&lt;/blockquote&gt;&#39;);
<a name="line182"></a>  var dom = field1.getEditableDomHelper();
<a name="line183"></a>  goog.dom.Range.createCaret(dom.getElement(&#39;quote&#39;), 2).select();
<a name="line184"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line185"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line186"></a>  var elem = field1.getElement();
<a name="line187"></a>  var secondBlockquote =
<a name="line188"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[1];
<a name="line189"></a>  assertHTMLEquals(&#39;two&lt;br&gt;&#39;, secondBlockquote.innerHTML);
<a name="line190"></a>
<a name="line191"></a>  // Verifies that a blockquote split doesn&#39;t happen if it doesn&#39;t need to.
<a name="line192"></a>  field1.setHtml(false,
<a name="line193"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;one&lt;br id=&quot;brcursor&quot;&gt;&lt;/blockquote&gt;&#39;);
<a name="line194"></a>  selectNodeAndHitEnter(field1, &#39;brcursor&#39;);
<a name="line195"></a>  assertEquals(
<a name="line196"></a>      1, dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem).length);
<a name="line197"></a>}
<a name="line198"></a>
<a name="line199"></a>
<a name="line200"></a>/**
<a name="line201"></a> * Tests that breaking in a text node before a BR doesn&#39;t result in unnecessary
<a name="line202"></a> * newlines.
<a name="line203"></a> * @bug 1471047
<a name="line204"></a> */
<a name="line205"></a>function testEnterInBlockquoteRemovesUnnecessaryBrWithCursorBeforeBr() {
<a name="line206"></a>  setUpFields(true);
<a name="line207"></a>
<a name="line208"></a>  // Assume the following HTML snippet:-
<a name="line209"></a>  // &lt;blockquote&gt;one|&lt;br&gt;two&lt;br&gt;&lt;/blockquote&gt;
<a name="line210"></a>  //
<a name="line211"></a>  // After enter on the cursor position, the resulting HTML should be.
<a name="line212"></a>  // &lt;blockquote&gt;one&lt;br&gt;&lt;/blockquote&gt;
<a name="line213"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line214"></a>  // &lt;blockquote&gt;two&lt;br&gt;&lt;/blockquote&gt;
<a name="line215"></a>  field1.setHtml(false,
<a name="line216"></a>      &#39;&lt;blockquote id=&quot;quote&quot; class=&quot;tr_bq&quot;&gt;one&lt;br&gt;&#39; +
<a name="line217"></a>      &#39;two&lt;br&gt;&lt;/blockquote&gt;&#39;);
<a name="line218"></a>  var dom = field1.getEditableDomHelper();
<a name="line219"></a>  var cursor = dom.getElement(&#39;quote&#39;).firstChild;
<a name="line220"></a>  goog.dom.Range.createCaret(cursor, 3).select();
<a name="line221"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line222"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line223"></a>  var elem = field1.getElement();
<a name="line224"></a>  var secondBlockquote =
<a name="line225"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[1];
<a name="line226"></a>  assertHTMLEquals(&#39;two&lt;br&gt;&#39;, secondBlockquote.innerHTML);
<a name="line227"></a>
<a name="line228"></a>  // Ensures that standard text node split works as expected with the new
<a name="line229"></a>  // change.
<a name="line230"></a>  field1.setHtml(false,
<a name="line231"></a>      &#39;&lt;blockquote id=&quot;quote&quot; class=&quot;tr_bq&quot;&gt;one&lt;b&gt;two&lt;/b&gt;&lt;br&gt;&#39;);
<a name="line232"></a>  cursor = dom.getElement(&#39;quote&#39;).firstChild;
<a name="line233"></a>  goog.dom.Range.createCaret(cursor, 3).select();
<a name="line234"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line235"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line236"></a>  secondBlockquote =
<a name="line237"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[1];
<a name="line238"></a>  assertHTMLEquals(&#39;&lt;b&gt;two&lt;/b&gt;&lt;br&gt;&#39;, secondBlockquote.innerHTML);
<a name="line239"></a>}
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * Tests that pressing enter in a blockquote doesn&#39;t create unnecessary
<a name="line244"></a> * DOM subtrees.
<a name="line245"></a> *
<a name="line246"></a> * @bug 1991539
<a name="line247"></a> * @bug 1991392
<a name="line248"></a> */
<a name="line249"></a>function testEnterInBlockquoteRemovesExtraNodes() {
<a name="line250"></a>  setUpFields(true);
<a name="line251"></a>
<a name="line252"></a>  // Let&#39;s assume we have the following DOM structure and the
<a name="line253"></a>  // cursor is placed after the first numbered list item &quot;one&quot;.
<a name="line254"></a>  //
<a name="line255"></a>  // &lt;blockquote class=&quot;tr_bq&quot;&gt;
<a name="line256"></a>  //   &lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li&gt;one|&lt;/li&gt;&lt;/div&gt;
<a name="line257"></a>  //   &lt;div&gt;two&lt;/div&gt;
<a name="line258"></a>  // &lt;/blockquote&gt;
<a name="line259"></a>  //
<a name="line260"></a>  // After pressing enter, we have the following structure.
<a name="line261"></a>  //
<a name="line262"></a>  // &lt;blockquote class=&quot;tr_bq&quot;&gt;
<a name="line263"></a>  //   &lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li&gt;one|&lt;/li&gt;&lt;/div&gt;
<a name="line264"></a>  // &lt;/blockquote&gt;
<a name="line265"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line266"></a>  // &lt;blockquote class=&quot;tr_bq&quot;&gt;
<a name="line267"></a>  //   &lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span id=&quot;&quot;&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
<a name="line268"></a>  //   &lt;div&gt;two&lt;/div&gt;
<a name="line269"></a>  // &lt;/blockquote&gt;
<a name="line270"></a>  //
<a name="line271"></a>  // This appears to the user as an empty list. After the fix, the HTML
<a name="line272"></a>  // will be
<a name="line273"></a>  //
<a name="line274"></a>  // &lt;blockquote class=&quot;tr_bq&quot;&gt;
<a name="line275"></a>  //   &lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li&gt;one|&lt;/li&gt;&lt;/div&gt;
<a name="line276"></a>  // &lt;/blockquote&gt;
<a name="line277"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line278"></a>  // &lt;blockquote class=&quot;tr_bq&quot;&gt;
<a name="line279"></a>  //   &lt;div&gt;two&lt;/div&gt;
<a name="line280"></a>  // &lt;/blockquote&gt;
<a name="line281"></a>  //
<a name="line282"></a>  field1.setHtml(false,
<a name="line283"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;&#39; +
<a name="line284"></a>      &#39;&lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li id=&quot;cursor&quot;&gt;one&lt;/li&gt;&lt;/div&gt;&#39; +
<a name="line285"></a>      &#39;&lt;div&gt;b&lt;/div&gt;&#39; +
<a name="line286"></a>      &#39;&lt;/blockquote&gt;&#39;);
<a name="line287"></a>  var dom = field1.getEditableDomHelper();
<a name="line288"></a>  goog.dom.Range.createCaret(dom.getElement(&#39;cursor&#39;).firstChild, 3).select();
<a name="line289"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line290"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line291"></a>  var elem = field1.getElement();
<a name="line292"></a>  var secondBlockquote =
<a name="line293"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[1];
<a name="line294"></a>  assertHTMLEquals(&#39;&lt;div&gt;b&lt;/div&gt;&#39;, secondBlockquote.innerHTML);
<a name="line295"></a>
<a name="line296"></a>  // Ensure that we remove only unnecessary subtrees.
<a name="line297"></a>  field1.setHtml(false,
<a name="line298"></a>      &#39;&lt;blockquote class=&quot;tr_bq&quot;&gt;&#39; +
<a name="line299"></a>      &#39;&lt;div&gt;&lt;span&gt;a&lt;/span&gt;&lt;div id=&quot;cursor&quot;&gt;one&lt;/div&gt;&lt;div&gt;two&lt;/div&gt;&lt;/div&gt;&#39; +
<a name="line300"></a>      &#39;&lt;div&gt;&lt;span&gt;c&lt;/span&gt;&lt;/div&gt;&#39; +
<a name="line301"></a>      &#39;&lt;/blockquote&gt;&#39;);
<a name="line302"></a>  goog.dom.Range.createCaret(dom.getElement(&#39;cursor&#39;).firstChild, 3).select();
<a name="line303"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line304"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line305"></a>  secondBlockquote =
<a name="line306"></a>      dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem)[1];
<a name="line307"></a>  var expectedHTML = &#39;&lt;div&gt;&lt;div&gt;two&lt;/div&gt;&lt;/div&gt;&#39; +
<a name="line308"></a>      &#39;&lt;div&gt;&lt;span&gt;c&lt;/span&gt;&lt;/div&gt;&#39;;
<a name="line309"></a>  assertHTMLEquals(expectedHTML, secondBlockquote.innerHTML);
<a name="line310"></a>
<a name="line311"></a>  // Place the cursor in the middle of a line.
<a name="line312"></a>  field1.setHtml(false,
<a name="line313"></a>      &#39;&lt;blockquote id=&quot;quote&quot; class=&quot;tr_bq&quot;&gt;&#39; +
<a name="line314"></a>      &#39;&lt;div&gt;one&lt;/div&gt;&lt;div&gt;two&lt;/div&gt;&#39; +
<a name="line315"></a>      &#39;&lt;/blockquote&gt;&#39;);
<a name="line316"></a>  goog.dom.Range.createCaret(
<a name="line317"></a>      dom.getElement(&#39;quote&#39;).firstChild.firstChild, 1).select();
<a name="line318"></a>  goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line319"></a>                                      goog.events.KeyCodes.ENTER);
<a name="line320"></a>  var blockquotes = dom.getElementsByTagNameAndClass(&#39;BLOCKQUOTE&#39;, null, elem);
<a name="line321"></a>  assertEquals(2, blockquotes.length);
<a name="line322"></a>  assertHTMLEquals(&#39;&lt;div&gt;o&lt;/div&gt;&#39;, blockquotes[0].innerHTML);
<a name="line323"></a>  assertHTMLEquals(&#39;&lt;div&gt;ne&lt;/div&gt;&lt;div&gt;two&lt;/div&gt;&#39;, blockquotes[1].innerHTML);
<a name="line324"></a>}
<a name="line325"></a>
<a name="line326"></a>function testEnterInList() {
<a name="line327"></a>  setUpFields(true);
<a name="line328"></a>
<a name="line329"></a>  // &lt;enter&gt; in a list should *never* be handled by custom code. Lists are
<a name="line330"></a>  // just way too complicated to get right.
<a name="line331"></a>  field1.setHtml(false,
<a name="line332"></a>      &#39;&lt;ol&gt;&lt;li&gt;hi!&lt;span id=&quot;field1cursor&quot;&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&#39;);
<a name="line333"></a>  if (goog.userAgent.OPERA) {
<a name="line334"></a>    // Opera doesn&#39;t actually place the selection in the empty span
<a name="line335"></a>    // unless we add a text node first.
<a name="line336"></a>    var dom = field1.getEditableDomHelper();
<a name="line337"></a>    dom.getElement(&#39;field1cursor&#39;).appendChild(dom.createTextNode(&#39;&#39;));
<a name="line338"></a>  }
<a name="line339"></a>  var prevented = !selectNodeAndHitEnter(field1, &#39;field1cursor&#39;);
<a name="line340"></a>  assertFalse(&#39;&lt;enter&gt; in a list should not be prevented&#39;, prevented);
<a name="line341"></a>}
<a name="line342"></a>
<a name="line343"></a>function testEnterAtEndOfBlockInWebkit() {
<a name="line344"></a>  setUpFields(true);
<a name="line345"></a>
<a name="line346"></a>  if (goog.userAgent.WEBKIT) {
<a name="line347"></a>    field1.setHtml(false,
<a name="line348"></a>        &#39;&lt;blockquote&gt;hi!&lt;span id=&quot;field1cursor&quot;&gt;&lt;/span&gt;&lt;/blockquote&gt;&#39;);
<a name="line349"></a>
<a name="line350"></a>    var cursor = field1.getEditableDomHelper().getElement(&#39;field1cursor&#39;);
<a name="line351"></a>    goog.editor.range.placeCursorNextTo(cursor, false);
<a name="line352"></a>    goog.dom.removeNode(cursor);
<a name="line353"></a>
<a name="line354"></a>    var prevented = !goog.testing.events.fireKeySequence(
<a name="line355"></a>        field1.getElement(), goog.events.KeyCodes.ENTER);
<a name="line356"></a>    waitForChangeEvents();
<a name="line357"></a>    assertChangeFlags();
<a name="line358"></a>    assert(&#39;event should have been prevented&#39;, prevented);
<a name="line359"></a>
<a name="line360"></a>    // Make sure that the block now has two brs.
<a name="line361"></a>    var elem = field1.getElement();
<a name="line362"></a>    assertEquals(&#39;should have inserted two br tags: &#39; + elem.innerHTML,
<a name="line363"></a>        2, goog.dom.getElementsByTagNameAndClass(&#39;BR&#39;, null, elem).length);
<a name="line364"></a>  }
<a name="line365"></a>}
<a name="line366"></a>
<a name="line367"></a>
<a name="line368"></a>/**
<a name="line369"></a> * Tests that deleting a BR that comes right before a block element works.
<a name="line370"></a> * @bug 1471096
<a name="line371"></a> * @bug 2056376
<a name="line372"></a> */
<a name="line373"></a>function testDeleteBrBeforeBlock() {
<a name="line374"></a>  setUpFields(true);
<a name="line375"></a>
<a name="line376"></a>  // This test only works on Gecko, because it&#39;s testing for manual deletion of
<a name="line377"></a>  // BR tags, which is done only for Gecko. For other browsers we fall through
<a name="line378"></a>  // and let the browser do the delete, which can only be tested with a robot
<a name="line379"></a>  // test (see javascript/apps/editor/tests/delete_br_robot.html).
<a name="line380"></a>  if (goog.userAgent.GECKO) {
<a name="line381"></a>    field1.setHtml(false, &#39;one&lt;br&gt;&lt;br&gt;&lt;div&gt;two&lt;/div&gt;&#39;);
<a name="line382"></a>    var helper = new goog.testing.editor.TestHelper(field1.getElement());
<a name="line383"></a>    helper.select(field1.getElement(), 2); // Between the two BR&#39;s.
<a name="line384"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line385"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line386"></a>    assertEquals(&#39;Should have deleted exactly one &lt;br&gt;&#39;,
<a name="line387"></a>                 &#39;one&lt;br&gt;&lt;div&gt;two&lt;/div&gt;&#39;,
<a name="line388"></a>                 field1.getElement().innerHTML);
<a name="line389"></a>
<a name="line390"></a>    // We test the case where the BR has a previous sibling which is not
<a name="line391"></a>    // a block level element.
<a name="line392"></a>    field1.setHtml(false, &#39;one&lt;br&gt;&lt;ul&gt;&lt;li&gt;two&lt;/li&gt;&lt;/ul&gt;&#39;);
<a name="line393"></a>    helper.select(field1.getElement(), 1); // Between one and BR.
<a name="line394"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line395"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line396"></a>    assertEquals(&#39;Should have deleted the &lt;br&gt;&#39;,
<a name="line397"></a>                 &#39;one&lt;ul&gt;&lt;li&gt;two&lt;/li&gt;&lt;/ul&gt;&#39;,
<a name="line398"></a>                 field1.getElement().innerHTML);
<a name="line399"></a>    // Verify that the cursor is placed at the end of the text node &quot;one&quot;.
<a name="line400"></a>    var range = field1.getRange();
<a name="line401"></a>    var focusNode = range.getFocusNode();
<a name="line402"></a>    assertTrue(&#39;The selected range should be collapsed&#39;, range.isCollapsed());
<a name="line403"></a>    assertTrue(&#39;The focus node should be the text node &quot;one&quot;&#39;,
<a name="line404"></a>               focusNode.nodeType == goog.dom.NodeType.TEXT &amp;&amp;
<a name="line405"></a>               focusNode.data == &#39;one&#39;);
<a name="line406"></a>    assertEquals(&#39;The focus offset should be at the end of the text node &quot;one&quot;&#39;,
<a name="line407"></a>                 focusNode.length,
<a name="line408"></a>                 range.getFocusOffset());
<a name="line409"></a>    assertTrue(&#39;The next sibling of the focus node should be the UL&#39;,
<a name="line410"></a>               focusNode.nextSibling &amp;&amp;
<a name="line411"></a>               focusNode.nextSibling.tagName == goog.dom.TagName.UL);
<a name="line412"></a>
<a name="line413"></a>    // We test the case where the previous sibling of the BR is a block
<a name="line414"></a>    // level element.
<a name="line415"></a>    field1.setHtml(false, &#39;&lt;div&gt;foo&lt;/div&gt;&lt;br&gt;&lt;div&gt;&lt;span&gt;bar&lt;/span&gt;&lt;/div&gt;&#39;);
<a name="line416"></a>    helper.select(field1.getElement(), 1); // Before the BR.
<a name="line417"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line418"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line419"></a>    assertEquals(&#39;Should have deleted the &lt;br&gt;&#39;,
<a name="line420"></a>                 &#39;&lt;div&gt;foo&lt;/div&gt;&lt;div&gt;&lt;span&gt;bar&lt;/span&gt;&lt;/div&gt;&#39;,
<a name="line421"></a>                 field1.getElement().innerHTML);
<a name="line422"></a>    range = field1.getRange();
<a name="line423"></a>    assertEquals(&#39;The selected range should be contained within the &lt;span&gt;&#39;,
<a name="line424"></a>                 goog.dom.TagName.SPAN,
<a name="line425"></a>                 range.getContainerElement().tagName);
<a name="line426"></a>    assertTrue(&#39;The selected range should be collapsed&#39;, range.isCollapsed());
<a name="line427"></a>    // Verify that the cursor is placed inside the span at the beginning of bar.
<a name="line428"></a>    focusNode = range.getFocusNode();
<a name="line429"></a>    assertTrue(&#39;The focus node should be the text node &quot;bar&quot;&#39;,
<a name="line430"></a>               focusNode.nodeType == goog.dom.NodeType.TEXT &amp;&amp;
<a name="line431"></a>               focusNode.data == &#39;bar&#39;);
<a name="line432"></a>    assertEquals(&#39;The focus offset should be at the beginning &#39; +
<a name="line433"></a>                 &#39;of the text node &quot;bar&quot;&#39;,
<a name="line434"></a>                 0,
<a name="line435"></a>                 range.getFocusOffset());
<a name="line436"></a>
<a name="line437"></a>    // We test the case where the BR does not have a previous sibling.
<a name="line438"></a>    field1.setHtml(false, &#39;&lt;br&gt;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&#39;);
<a name="line439"></a>    helper.select(field1.getElement(), 0); // Before the BR.
<a name="line440"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line441"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line442"></a>    assertEquals(&#39;Should have deleted the &lt;br&gt;&#39;,
<a name="line443"></a>                 &#39;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&#39;,
<a name="line444"></a>                 field1.getElement().innerHTML);
<a name="line445"></a>    range = field1.getRange();
<a name="line446"></a>    // Verify that the cursor is placed inside the LI at the text node &quot;one&quot;.
<a name="line447"></a>    assertEquals(&#39;The selected range should be contained within the &lt;li&gt;&#39;,
<a name="line448"></a>                 goog.dom.TagName.LI,
<a name="line449"></a>                 range.getContainerElement().tagName);
<a name="line450"></a>    assertTrue(&#39;The selected range should be collapsed&#39;, range.isCollapsed());
<a name="line451"></a>    focusNode = range.getFocusNode();
<a name="line452"></a>    assertTrue(&#39;The focus node should be the text node &quot;one&quot;&#39;,
<a name="line453"></a>               (focusNode.nodeType == goog.dom.NodeType.TEXT &amp;&amp;
<a name="line454"></a>                focusNode.data == &#39;one&#39;));
<a name="line455"></a>    assertEquals(&#39;The focus offset should be at the beginning of &#39; +
<a name="line456"></a>                 &#39;the text node &quot;one&quot;&#39;,
<a name="line457"></a>                 0,
<a name="line458"></a>                 range.getFocusOffset());
<a name="line459"></a>
<a name="line460"></a>    // Testing deleting a BR followed by a block level element and preceded
<a name="line461"></a>    // by a BR.
<a name="line462"></a>    field1.setHtml(false, &#39;&lt;br&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&#39;);
<a name="line463"></a>    helper.select(field1.getElement(), 1); // Between the BR&#39;s.
<a name="line464"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line465"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line466"></a>    assertEquals(&#39;Should have deleted the &lt;br&gt;&#39;,
<a name="line467"></a>                 &#39;&lt;br&gt;&lt;ul&gt;&lt;li&gt;one&lt;/li&gt;&lt;/ul&gt;&#39;,
<a name="line468"></a>                 field1.getElement().innerHTML);
<a name="line469"></a>    // Verify that the cursor is placed inside the LI at the text node &quot;one&quot;.
<a name="line470"></a>    range = field1.getRange();
<a name="line471"></a>    assertEquals(&#39;The selected range should be contained within the &lt;li&gt;&#39;,
<a name="line472"></a>                 goog.dom.TagName.LI,
<a name="line473"></a>                 range.getContainerElement().tagName);
<a name="line474"></a>    assertTrue(&#39;The selected range should be collapsed&#39;, range.isCollapsed());
<a name="line475"></a>    focusNode = range.getFocusNode();
<a name="line476"></a>    assertTrue(&#39;The focus node should be the text node &quot;one&quot;&#39;,
<a name="line477"></a>               (focusNode.nodeType == goog.dom.NodeType.TEXT &amp;&amp;
<a name="line478"></a>                focusNode.data == &#39;one&#39;));
<a name="line479"></a>    assertEquals(&#39;The focus offset should be at the beginning of &#39; +
<a name="line480"></a>                 &#39;the text node &quot;one&quot;&#39;,
<a name="line481"></a>                 0,
<a name="line482"></a>                 range.getFocusOffset());
<a name="line483"></a>  } // End if GECKO
<a name="line484"></a>}
<a name="line485"></a>
<a name="line486"></a>
<a name="line487"></a>/**
<a name="line488"></a> * Tests that deleting a BR before a blockquote doesn&#39;t remove quoted text.
<a name="line489"></a> * @bug 1471075
<a name="line490"></a> */
<a name="line491"></a>function testDeleteBeforeBlockquote() {
<a name="line492"></a>  setUpFields(true);
<a name="line493"></a>
<a name="line494"></a>  if (goog.userAgent.GECKO) {
<a name="line495"></a>    field1.setHtml(false,
<a name="line496"></a>                   &#39;&lt;br&gt;&lt;br&gt;&lt;div&gt;&lt;br&gt;&lt;blockquote&gt;foo&lt;/blockquote&gt;&lt;/div&gt;&#39;);
<a name="line497"></a>    var helper = new goog.testing.editor.TestHelper(field1.getElement());
<a name="line498"></a>    helper.select(field1.getElement(), 0); // Before the first BR.
<a name="line499"></a>    // Fire three deletes in quick succession.
<a name="line500"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line501"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line502"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line503"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line504"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line505"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line506"></a>    assertEquals(&#39;Should have deleted all the &lt;br&gt;\&#39;s and the blockquote &#39; +
<a name="line507"></a>                 &#39;isn\&#39;t affected&#39;,
<a name="line508"></a>                 &#39;&lt;div&gt;&lt;blockquote&gt;foo&lt;/blockquote&gt;&lt;/div&gt;&#39;,
<a name="line509"></a>                 field1.getElement().innerHTML);
<a name="line510"></a>    var range = field1.getRange();
<a name="line511"></a>    assertEquals(&#39;The selected range should be contained within the &#39; +
<a name="line512"></a>                 &#39;&lt;blockquote&gt;&#39;,
<a name="line513"></a>                 goog.dom.TagName.BLOCKQUOTE,
<a name="line514"></a>                 range.getContainerElement().tagName);
<a name="line515"></a>    assertTrue(&#39;The selected range should be collapsed&#39;, range.isCollapsed());
<a name="line516"></a>    var focusNode = range.getFocusNode();
<a name="line517"></a>    assertTrue(&#39;The focus node should be the text node &quot;foo&quot;&#39;,
<a name="line518"></a>               (focusNode.nodeType == goog.dom.NodeType.TEXT &amp;&amp;
<a name="line519"></a>                focusNode.data == &#39;foo&#39;));
<a name="line520"></a>    assertEquals(&#39;The focus offset should be at the &#39; +
<a name="line521"></a>                 &#39;beginning of the text node &quot;foo&quot;&#39;,
<a name="line522"></a>                 0,
<a name="line523"></a>                 range.getFocusOffset());
<a name="line524"></a>  }
<a name="line525"></a>}
<a name="line526"></a>
<a name="line527"></a>
<a name="line528"></a>/**
<a name="line529"></a> * Tests that deleting a BR is working normally (that the workaround for the
<a name="line530"></a> * bug is not causing double deletes).
<a name="line531"></a> * @bug 1471096
<a name="line532"></a> */
<a name="line533"></a>function testDeleteBrNormal() {
<a name="line534"></a>  setUpFields(true);
<a name="line535"></a>
<a name="line536"></a>  // This test only works on Gecko, because it&#39;s testing for manual deletion of
<a name="line537"></a>  // BR tags, which is done only for Gecko. For other browsers we fall through
<a name="line538"></a>  // and let the browser do the delete, which can only be tested with a robot
<a name="line539"></a>  // test (see javascript/apps/editor/tests/delete_br_robot.html).
<a name="line540"></a>  if (goog.userAgent.GECKO) {
<a name="line541"></a>
<a name="line542"></a>    field1.setHtml(false, &#39;one&lt;br&gt;&lt;br&gt;&lt;br&gt;two&#39;);
<a name="line543"></a>    var helper = new goog.testing.editor.TestHelper(field1.getElement());
<a name="line544"></a>    helper.select(field1.getElement(), 2); // Between the first and second BR&#39;s.
<a name="line545"></a>    field1.getElement().focus();
<a name="line546"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line547"></a>                                        goog.events.KeyCodes.DELETE);
<a name="line548"></a>    assertEquals(&#39;Should have deleted exactly one &lt;br&gt;&#39;,
<a name="line549"></a>                 &#39;one&lt;br&gt;&lt;br&gt;two&#39;,
<a name="line550"></a>                 field1.getElement().innerHTML);
<a name="line551"></a>
<a name="line552"></a>  } // End if GECKO
<a name="line553"></a>}
<a name="line554"></a>
<a name="line555"></a>
<a name="line556"></a>/**
<a name="line557"></a> * Tests that deleteCursorSelectionW3C_ correctly recognizes visually
<a name="line558"></a> * collapsed selections in Opera even if they contain a &lt;br&gt;.
<a name="line559"></a> * See the deleteCursorSelectionW3C_ comment in enterhandler.js.
<a name="line560"></a> */
<a name="line561"></a>function testCollapsedSelectionKeepsBrOpera() {
<a name="line562"></a>  setUpFields(true);
<a name="line563"></a>
<a name="line564"></a>  if (goog.userAgent.OPERA) {
<a name="line565"></a>    field1.setHtml(false, &#39;&lt;div&gt;&lt;br id=&quot;pleasedontdeleteme&quot;&gt;&lt;/div&gt;&#39;);
<a name="line566"></a>    field1.focus();
<a name="line567"></a>    goog.testing.events.fireKeySequence(field1.getElement(),
<a name="line568"></a>                                        goog.events.KeyCodes.ENTER);
<a name="line569"></a>    assertNotNull(&#39;The &lt;br&gt; must not have been deleted&#39;,
<a name="line570"></a>                  goog.dom.getElement(&#39;pleasedontdeleteme&#39;));
<a name="line571"></a>  }
<a name="line572"></a>}
<a name="line573"></a>
<a name="line574"></a>
<a name="line575"></a>/**
<a name="line576"></a> * Selects the node at the given id, and simulates an ENTER keypress.
<a name="line577"></a> * @param {goog.editor.Field} field The field with the node.
<a name="line578"></a> * @param {string} id A DOM id.
<a name="line579"></a> * @return {boolean} Whether preventDefault was called on the event.
<a name="line580"></a> */
<a name="line581"></a>function selectNodeAndHitEnter(field, id) {
<a name="line582"></a>  var dom = field.getEditableDomHelper();
<a name="line583"></a>  var cursor = dom.getElement(id);
<a name="line584"></a>  goog.dom.Range.createFromNodeContents(cursor).select();
<a name="line585"></a>  return goog.testing.events.fireKeySequence(
<a name="line586"></a>      cursor, goog.events.KeyCodes.ENTER);
<a name="line587"></a>}
<a name="line588"></a>
<a name="line589"></a>
<a name="line590"></a>/**
<a name="line591"></a> * Creates a field with only the enter handler plugged in, for testing.
<a name="line592"></a> * @param {string} id A DOM id.
<a name="line593"></a> * @return {goog.editor.Field} A field.
<a name="line594"></a> */
<a name="line595"></a>function makeField(id, classnameRequiredToSplitBlockquote) {
<a name="line596"></a>  var field = new goog.editor.Field(id);
<a name="line597"></a>  field.registerPlugin(new goog.editor.plugins.EnterHandler());
<a name="line598"></a>  field.registerPlugin(new goog.editor.plugins.Blockquote(
<a name="line599"></a>      classnameRequiredToSplitBlockquote));
<a name="line600"></a>
<a name="line601"></a>  goog.events.listen(field, goog.editor.Field.EventType.BEFORECHANGE,
<a name="line602"></a>      function() {
<a name="line603"></a>        // set the global flag that beforechange was fired.
<a name="line604"></a>        firedBeforeChange = true;
<a name="line605"></a>      });
<a name="line606"></a>  goog.events.listen(field, goog.editor.Field.EventType.DELAYEDCHANGE,
<a name="line607"></a>      function() {
<a name="line608"></a>        // set the global flag that delayed change was fired.
<a name="line609"></a>        firedDelayedChange = true;
<a name="line610"></a>      });
<a name="line611"></a>
<a name="line612"></a>  return field;
<a name="line613"></a>}
<a name="line614"></a>
<a name="line615"></a>
<a name="line616"></a>/**
<a name="line617"></a> * Reset all the global flags related to change events.
<a name="line618"></a> */
<a name="line619"></a>function resetChangeFlags() {
<a name="line620"></a>  waitForChangeEvents();
<a name="line621"></a>  firedBeforeChange = firedDelayedChange = false;
<a name="line622"></a>}
<a name="line623"></a>
<a name="line624"></a>
<a name="line625"></a>/**
<a name="line626"></a> * Asserts that both change flags were fired since the last reset.
<a name="line627"></a> */
<a name="line628"></a>function assertChangeFlags() {
<a name="line629"></a>  assert(&#39;Beforechange should have fired&#39;, firedBeforeChange);
<a name="line630"></a>  assert(&#39;Delayedchange should have fired&#39;, firedDelayedChange);
<a name="line631"></a>}
<a name="line632"></a>
<a name="line633"></a>
<a name="line634"></a>/**
<a name="line635"></a> * Wait for delayedchange to propagate.
<a name="line636"></a> */
<a name="line637"></a>function waitForChangeEvents() {
<a name="line638"></a>  clock.tick(goog.editor.Field.DELAYED_CHANGE_FREQUENCY +
<a name="line639"></a>      goog.editor.Field.CHANGE_FREQUENCY);
<a name="line640"></a>}
<a name="line641"></a>
<a name="line642"></a>function getNbsp() {
<a name="line643"></a>  // On WebKit (pre-528) and Opera, &amp;nbsp; shows up as its unicode character in
<a name="line644"></a>  // innerHTML under some circumstances.
<a name="line645"></a>  return (goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;528&#39;)) ||
<a name="line646"></a>         goog.userAgent.OPERA ? &#39;\u00a0&#39; : &#39;&amp;nbsp;&#39;;
<a name="line647"></a>}
<a name="line648"></a>
<a name="line649"></a>
<a name="line650"></a>function testPrepareContent() {
<a name="line651"></a>  setUpFields(true);
<a name="line652"></a>  assertPreparedContents(&#39;hi&#39;, &#39;hi&#39;);
<a name="line653"></a>  assertPreparedContents(
<a name="line654"></a>      goog.editor.BrowserFeature.COLLAPSES_EMPTY_NODES ? &#39;&lt;br&gt;&#39; : &#39;&#39;, &#39;   &#39;);
<a name="line655"></a>}
<a name="line656"></a>
<a name="line657"></a>
<a name="line658"></a>/**
<a name="line659"></a> * Assert that the prepared contents matches the expected.
<a name="line660"></a> */
<a name="line661"></a>function assertPreparedContents(expected, original) {
<a name="line662"></a>  assertEquals(expected,
<a name="line663"></a>      field1.reduceOp_(
<a name="line664"></a>          goog.editor.Plugin.Op.PREPARE_CONTENTS_HTML, original));
<a name="line665"></a>}
<a name="line666"></a>
<a name="line667"></a>// UTILITY FUNCTION TESTS.
<a name="line668"></a>
<a name="line669"></a>function testDeleteW3CSimple() {
<a name="line670"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line671"></a>    container.innerHTML = &#39;&lt;div&gt;abcd&lt;/div&gt;&#39;;
<a name="line672"></a>    var range = goog.dom.Range.createFromNodes(container.firstChild.firstChild,
<a name="line673"></a>        1, container.firstChild.firstChild, 3);
<a name="line674"></a>    range.select();
<a name="line675"></a>    goog.editor.plugins.EnterHandler.deleteW3cRange_(range);
<a name="line676"></a>
<a name="line677"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;ad&lt;/div&gt;&#39;, container);
<a name="line678"></a>  }
<a name="line679"></a>}
<a name="line680"></a>
<a name="line681"></a>function testDeleteW3CAll() {
<a name="line682"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line683"></a>    container.innerHTML = &#39;&lt;div&gt;abcd&lt;/div&gt;&#39;;
<a name="line684"></a>    var range = goog.dom.Range.createFromNodes(container.firstChild.firstChild,
<a name="line685"></a>        0, container.firstChild.firstChild, 4);
<a name="line686"></a>    range.select();
<a name="line687"></a>    goog.editor.plugins.EnterHandler.deleteW3cRange_(range);
<a name="line688"></a>
<a name="line689"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&#39;, container);
<a name="line690"></a>  }
<a name="line691"></a>}
<a name="line692"></a>
<a name="line693"></a>function testDeleteW3CPartialEnd() {
<a name="line694"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line695"></a>    container.innerHTML = &#39;&lt;div&gt;ab&lt;/div&gt;&lt;div&gt;cd&lt;/div&gt;&#39;;
<a name="line696"></a>    var range = goog.dom.Range.createFromNodes(container.firstChild.firstChild,
<a name="line697"></a>        1, container.lastChild.firstChild, 1);
<a name="line698"></a>    range.select();
<a name="line699"></a>    goog.editor.plugins.EnterHandler.deleteW3cRange_(range);
<a name="line700"></a>
<a name="line701"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;ad&lt;/div&gt;&#39;, container);
<a name="line702"></a>  }
<a name="line703"></a>}
<a name="line704"></a>
<a name="line705"></a>function testDeleteW3CNonPartialEnd() {
<a name="line706"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line707"></a>    container.innerHTML = &#39;&lt;div&gt;ab&lt;/div&gt;&lt;div&gt;cd&lt;/div&gt;&#39;;
<a name="line708"></a>    var range = goog.dom.Range.createFromNodes(container.firstChild.firstChild,
<a name="line709"></a>        1, container.lastChild.firstChild, 2);
<a name="line710"></a>    range.select();
<a name="line711"></a>    goog.editor.plugins.EnterHandler.deleteW3cRange_(range);
<a name="line712"></a>
<a name="line713"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;&lt;div&gt;a&lt;/div&gt;&#39;, container);
<a name="line714"></a>  }
<a name="line715"></a>}
<a name="line716"></a>
<a name="line717"></a>function testIsInOneContainer() {
<a name="line718"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line719"></a>    container.innerHTML = &#39;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&#39;;
<a name="line720"></a>    var div = container.firstChild;
<a name="line721"></a>    var range = goog.dom.Range.createFromNodes(div, 0, div, 1);
<a name="line722"></a>    range.select();
<a name="line723"></a>    assertTrue(&#39;Selection must be recognized as being in one container&#39;,
<a name="line724"></a>        goog.editor.plugins.EnterHandler.isInOneContainerW3c_(range));
<a name="line725"></a>  }
<a name="line726"></a>}
<a name="line727"></a>
<a name="line728"></a>function testDeletingEndNodesWithNoNewLine() {
<a name="line729"></a>  if (goog.editor.BrowserFeature.HAS_W3C_RANGES) {
<a name="line730"></a>    container.innerHTML =
<a name="line731"></a>        &#39;a&lt;div&gt;b&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;c&lt;/div&gt;&lt;div&gt;d&lt;/div&gt;&#39;;
<a name="line732"></a>    var range = goog.dom.Range.createFromNodes(
<a name="line733"></a>        container.childNodes[2], 0, container.childNodes[4].childNodes[0], 1);
<a name="line734"></a>    range.select();
<a name="line735"></a>    var newRange = goog.editor.plugins.EnterHandler.deleteW3cRange_(range);
<a name="line736"></a>    goog.testing.dom.assertHtmlContentsMatch(&#39;a&lt;div&gt;b&lt;/div&gt;&#39;, container);
<a name="line737"></a>    assertTrue(newRange.isCollapsed());
<a name="line738"></a>    assertEquals(container, newRange.getStartNode());
<a name="line739"></a>    assertEquals(2, newRange.getStartOffset());
<a name="line740"></a>  }
<a name="line741"></a>}
</pre>


</body>
</html>
